package com.example.qiao;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.example.mylibrary.mvp.view.BaseActivity;
import com.example.qiao.adapter.ViewPageAdapter;
import com.example.qiao.mvp.view.TouActivity;
import com.google.android.material.tabs.TabLayout;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private TabLayout tl;
    private ViewPager vp;
    private List<String > list=new ArrayList<>();
    private android.widget.ImageView im;
    private SlidingMenu slidingMenu;
    ImageView iv;

    @Override
    public int bongLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        tl = (TabLayout) findViewById(R.id.tl);
        vp = (ViewPager) findViewById(R.id.vp);
        list.add("关注");
        list.add("发现");
        list.add("同城");
        im = (ImageView) findViewById(R.id.im);
    }
    @Override
    public void initData() {
        //抽屉
        im.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                slidingMenu.toggle();
            }
        });
        slidingMenu=new SlidingMenu(this);
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setBehindOffset(200);
        slidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
        View inflate = LayoutInflater.from(this).inflate(R.layout.sliding, null);

        iv = inflate.findViewById(R.id.iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(MainActivity.this, TouActivity.class),100);
            }
        });
        slidingMenu.setMenu(inflate);


        //TabLayout
        for (int i = 0; i < list.size(); i++) {
            tl.addTab(tl.newTab().setText(list.get(i)));
        }

        //设置适配器
        ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager());
        vp.setAdapter(viewPageAdapter);
        tl.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

//    回传
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==100&& resultCode==RESULT_OK){
            if(SPUtils.getInstance().getString("img")!=null){
                Glide.with(this).load(SPUtils.getInstance().getString("img"))
                        .transform(new CircleCrop())
                        .into(iv);
            }
        }

    }
}
